#!/usr/bin/env python
# encoding: utf-8
"""
construct_graph.py

Created by Bud Gibson on 2010-07-06.
Copyright (c) 2010 Algorithmic Advertising. All rights reserved.
"""
try:
  from buzztracker.analytics.group_compare import group_in_out_labeled,\
    group_non_reciprocator, group_intersection
  from buzztracker.utilities.sorters import sort_displayName
  from buzztracker.REST.poco_public import list_profile_stubs, followers_of,\
    followed_by
except ImportError:
  import sys
  import os
  sys.path.append(os.path.join(os.path.dirname(__file__), '../..'))
  from buzztracker.analytics.group_compare import group_in_out_labeled,\
    group_non_reciprocator, group_intersection
  from buzztracker.utilities.sorters import sort_displayName
  from buzztracker.REST.poco_public import list_profile_stubs, followers_of,\
    followed_by

def base_graph(participants):
  """Shows critical elements of participants' buzz networks"""
  participants = list_profile_stubs(participants)
  for participant in participants:
    followers = \
      group_in_out_labeled(followers_of(participant['id']), participants)
    following = \
      group_in_out_labeled(followed_by(participant['id']), participants)
    participant['mutual'] = \
      group_intersection(following, followers)
    participant['mutual_count'] = len(participant['mutual'])
    participant['unreciprocated'] = \
      group_non_reciprocator(following, 
        followers)
    participant['unreciprocated_count'] = len(participant['unreciprocated'])
    participant['otherFollowers'] = \
      group_non_reciprocator(followers, 
        following)
    participant['otherFollowers_count'] = len(participant['otherFollowers'])
    for item in ['mutual','unreciprocated','otherFollowers']:
      participant[item].sort(sort_displayName)
  participants.sort(sort_displayName)
  return participants

def main():
  import pprint
  pp = pprint.PrettyPrinter(depth=2)
  people = ['fpgibson', 'kristine.a.adams', 'ericwortman', 'meghan.shipley']
  pp.pprint(base_graph(people))

if __name__ == '__main__':
  main()

